function _toConsumableArray(arr) {
  return (
    _arrayWithoutHoles(arr) ||
    _iterableToArray(arr) ||
    _unsupportedIterableToArray(arr) ||
    _nonIterableSpread()
  );
}
function _nonIterableSpread() {
  throw new TypeError(
    'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
  );
}
function _unsupportedIterableToArray(o, minLen) {
  if (!o) return;
  if (typeof o === 'string') return _arrayLikeToArray(o, minLen);
  var n = Object.prototype.toString.call(o).slice(8, -1);
  if (n === 'Object' && o.constructor) n = o.constructor.name;
  if (n === 'Map' || n === 'Set') return Array.from(o);
  if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
    return _arrayLikeToArray(o, minLen);
}
function _iterableToArray(iter) {
  if (
    (typeof Symbol !== 'undefined' && iter[Symbol.iterator] != null) ||
    iter['@@iterator'] != null
  )
    return Array.from(iter);
}
function _arrayWithoutHoles(arr) {
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _arrayLikeToArray(arr, len) {
  if (len == null || len > arr.length) len = arr.length;
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  return arr2;
}
import * as Rules from '../_utils/consts/rules';

/**
 * 获取校验规则
 * @param props
 * @returns
 */
export var getRulesFromProps = function getRulesFromProps(props, form) {
  var _props$rules;
  var rules = [];
  if (
    props.required !== false &&
    !(
      (_props$rules = props.rules) !== null &&
      _props$rules !== void 0 &&
      _props$rules.some(function (rule) {
        return typeof rule === 'function' || rule.required;
      })
    )
  ) {
    var _props$label;
    rules.push({
      required: true,
      whitespace: true,
      message: '\u8BF7\u8F93\u5165'.concat(
        (_props$label = props.label) !== null && _props$label !== void 0 ? _props$label : '',
      ),
    });
  }
  if (props.valueType && Rules[props.valueType]) {
    var valueType = props.valueType;
    rules.push(Rules[valueType]);
  }

  // 防止 xss 攻击
  rules.push(Rules.xss);
  if (form && props.rules) {
    rules = [].concat(_toConsumableArray(rules), _toConsumableArray(props.rules));
  }
  return rules;
};
